package com.zzh.bc.modules.jks.dao;

import com.zzh.bc.base.impl.BaseDaoImpl;
import com.zzh.bc.db.MySQLExecute;
import com.zzh.bc.db.RSUtils;
import com.zzh.bc.model.JksModel;
import com.zzh.bc.model.PageModel;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;

public class JksDao extends BaseDaoImpl<JksModel> {
    @Override
    public JksModel findObjById(String id) {
        JksModel model = null;
        try {
            Optional<ResultSet> optional = MySQLExecute.findObjById(JksModel.class, "jks_id=?", id);
            if (optional.isPresent()){
                model =  RSUtils.cast2Bean(optional.get(), JksModel.class);
            }
        } catch (SQLException | IllegalAccessException | InstantiationException ex) {
            ex.printStackTrace();
        }
        return model;
    }

    @Override
    public List<JksModel> findAllObjByPage(PageModel pageModel) {

        try {
            System.out.println("查询所有的JKS文件。");
            Optional<ResultSet> all = MySQLExecute.findAll(JksModel.class, "LIMIT ?,?", pageModel.getOffset(), pageModel.getPageSize());
            if (all.isPresent()) {
                return RSUtils.cast2ListBean(all.get(), JksModel.class);
            }
        } catch (SQLException | IllegalAccessException | InstantiationException ex) {

            System.out.println(ex.getMessage());
        }


        return null;
    }
}
